﻿package baseEngine.utils
{
    import flash.geom.*;

    public class Vector3DUtils extends Object
    {
        public static const UP:Vector3D = new Vector3D(0, 1, 0);
        public static const DOWN:Vector3D = new Vector3D(0, -1, 0);
        public static const RIGHT:Vector3D = new Vector3D(1, 0, 0);
        public static const LEFT:Vector3D = new Vector3D(-1, 0, 0);
        public static const FORWARD:Vector3D = new Vector3D(0, 0, 1);
        public static const BACK:Vector3D = new Vector3D(0, 0, -1);
        public static const ZERO:Vector3D = new Vector3D(0, 0, 0);
        public static const ONE:Vector3D = new Vector3D(1, 1, 1);

        public function Vector3DUtils()
        {
            return;
        }// end function

        public static function lengthSquared(param1:Vector3D, param2:Vector3D) : Number
        {
            var _loc_3:* = param1.x - param2.x;
            var _loc_4:* = param1.y - param2.y;
            var _loc_5:* = param1.z - param2.z;
            return _loc_3 * _loc_3 + _loc_4 * _loc_4 + _loc_5 * _loc_5;
        }// end function

        public static function length(param1:Vector3D, param2:Vector3D) : Number
        {
            var _loc_3:* = param1.x - param2.x;
            var _loc_4:* = param1.y - param2.y;
            var _loc_5:* = param1.z - param2.z;
            return Math.sqrt(_loc_3 * _loc_3 + _loc_4 * _loc_4 + _loc_5 * _loc_5);
        }// end function

        public static function setLength(param1:Vector3D, param2:Number) : void
        {
            var _loc_3:* = param1.length;
            if (_loc_3 > 0)
            {
                _loc_3 = _loc_3 / param2;
                param1.x = param1.x / _loc_3;
                param1.y = param1.y / _loc_3;
                param1.z = param1.z / _loc_3;
            }
            else
            {
                var _loc_4:int = 0;
                param1.z = 0;
                var _loc_4:* = _loc_4;
                param1.y = _loc_4;
                param1.x = _loc_4;
            }
            return;
        }// end function

        public static function cross(param1:Vector3D, param2:Vector3D, param3:Vector3D = null) : Vector3D
        {
            if (!param3)
            {
                param3 = new Vector3D();
            }
            param3.x = param1.y * param2.z - param1.z * param2.y;
            param3.y = param1.z * param2.x - param1.x * param2.z;
            param3.z = param1.x * param2.y - param1.y * param2.x;
            return param3;
        }// end function

        public static function sub(param1:Vector3D, param2:Vector3D, param3:Vector3D = null) : Vector3D
        {
            if (!param3)
            {
                param3 = new Vector3D();
            }
            param3.x = param1.x - param2.x;
            param3.y = param1.y - param2.y;
            param3.z = param1.z - param2.z;
            return param3;
        }// end function

        public static function add(param1:Vector3D, param2:Vector3D, param3:Vector3D = null) : Vector3D
        {
            if (!param3)
            {
                param3 = new Vector3D();
            }
            param3.x = param1.x + param2.x;
            param3.y = param1.y + param2.y;
            param3.z = param1.z + param2.z;
            return param3;
        }// end function

        public static function set(param1:Vector3D, param2:Number = 0, param3:Number = 0, param4:Number = 0, param5:Number = 0) : void
        {
            param1.x = param2;
            param1.y = param3;
            param1.z = param4;
            param1.w = param5;
            return;
        }// end function

        public static function negate(param1:Vector3D, param2:Vector3D = null) : Vector3D
        {
            if (!param2)
            {
                param2 = new Vector3D();
            }
            param2.x = -param1.x;
            param2.y = -param1.y;
            param2.z = -param1.z;
            return param2;
        }// end function

        public static function interpolate(param1:Vector3D, param2:Vector3D, param3:Number, param4:Vector3D = null) : Vector3D
        {
            if (!param4)
            {
                param4 = new Vector3D();
            }
            param4.x = param1.x + (param2.x - param1.x) * param3;
            param4.y = param1.y + (param2.y - param1.y) * param3;
            param4.z = param1.z + (param2.z - param1.z) * param3;
            return param4;
        }// end function

        public static function random(param1:Number, param2:Number, param3:Vector3D = null) : Vector3D
        {
            if (!param3)
            {
                param3 = new Vector3D();
            }
            param3.x = Math.random() * (param2 - param1) + param1;
            param3.y = Math.random() * (param2 - param1) + param1;
            param3.z = Math.random() * (param2 - param1) + param1;
            return param3;
        }// end function

        public static function mirror(param1:Vector3D, param2:Vector3D, param3:Vector3D = null) : Vector3D
        {
            if (!param3)
            {
                param3 = new Vector3D();
            }
            var _loc_4:* = param1.dotProduct(param2);
            param3.x = param1.x - 2 * param2.x * _loc_4;
            param3.y = param1.y - 2 * param2.y * _loc_4;
            param3.z = param1.z - 2 * param2.z * _loc_4;
            return param3;
        }// end function

        public static function min(param1:Vector3D, param2:Vector3D, param3:Vector3D = null) : Vector3D
        {
            if (!param3)
            {
                param3 = new Vector3D();
            }
            param3.x = param1.x < param2.x ? (param1.x) : (param2.x);
            param3.y = param1.y < param2.y ? (param1.y) : (param2.y);
            param3.z = param1.z < param2.z ? (param1.z) : (param2.z);
            return param3;
        }// end function

        public static function max(param1:Vector3D, param2:Vector3D, param3:Vector3D = null) : Vector3D
        {
            if (!param3)
            {
                param3 = new Vector3D();
            }
            param3.x = param1.x > param2.x ? (param1.x) : (param2.x);
            param3.y = param1.y > param2.y ? (param1.y) : (param2.y);
            param3.z = param1.z > param2.z ? (param1.z) : (param2.z);
            return param3;
        }// end function

        public static function abs(param1:Vector3D) : void
        {
            if (param1.x < 0)
            {
                param1.x = -param1.x;
            }
            if (param1.y < 0)
            {
                param1.y = -param1.y;
            }
            if (param1.z < 0)
            {
                param1.z = -param1.z;
            }
            return;
        }// end function

    }
}
